library Wave10e initializer init requires LegacySystem

    private function MarineCommandChapter2 takes nothing returns nothing
        call SetPlayerTechResearched(GetEnumPlayer(),'R004',1) //Gunship Support
        call SetPlayerTechResearched(GetEnumPlayer(),'R00Z',1) //IUL Fire Mission
    endfunction
	
	private function Wave10Creeps takes nothing returns nothing
        call PlatoonReinforcements.execute()
        set udg_ACA[12] = true
        call ForForce(udg_EchoCompany,function MarineCommandChapter2)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "0320 Local Time" )
        call C130Wave10.execute()
        if udg_Mode==4 and udg_Players>0 then
            call ALICEText(10.0, "Chapter 1 Complete. |cff1e90ff100 XP|r awarded to " + GetPlayerName(ConvertedPlayer(udg_Sorted[1])) )
            set udg_Experience[udg_Sorted[1]] = udg_Experience[udg_Sorted[1]] + 100
        endif
        call PolledWait(30.0*udg_Pace)
        call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'n004',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnEastBottom,Player(13),'n003',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(14),'z002',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnTownWestCave,Player(13),'n004',2+udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'n004',2+udg_Spawn)
        call RandomSpawn('u000',2,GetRandomInt(0,udg_Spawn)) //Futty
        call SpawnRectRandom(gg_rct_SpawnWestTop,Player(14),'n004',2+udg_Spawn)
        call RandomSpawn('z00C',2,GetRandomInt(0,1)) //Assasin
        call RandomSpawn('n002',1,GetRandomInt(0,udg_Spawn)) //Devourer
        if udg_Players==udg_InitialPlayers then
            call GankMarine(Player(13),'u005',2+udg_Spawn,1600,2000)
        endif
        call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'nsw1',udg_InitialPlayers)
        call GankMarine(Player(13),'n004',2+udg_Spawn,1600,2000)
        call GankMarine(Player(13),'n004',2+udg_Spawn,1600,2000)
        call PolledWait(30.0*udg_Pace)
        call RandomSpawn('u00L',4,IMinBJ(5, udg_Players)) //Blink
        call GankMarine(Player(14),'n004',2+udg_Spawn,1600,2000)
        call GankMarine(Player(14),'n004',2+udg_Spawn,1600,2000)
        if udg_Players>=6 then
            call RandomSpawn('ugar',1,2)
            call RandomSpawn('n002',1,2)
        endif
        call PolledWait(30.0*udg_Pace)
        call RandomSpawn('ugar',1,GetRandomInt(1,udg_Spawn)) //Gargoyle
        call GankMarine(Player(13),'n005',2+udg_Spawn,1600,2000)
    endfunction
	
    private function PowerOn takes nothing returns nothing
        local unit u
        local integer i = 1
        call CreateUnit(Player(0),'e00P',13685.0,-5560.0,0.0)
        call TriggerSleepAction(0.)
        call CreateUnit(Player(0),'e00P',13878.0,-5367.0,0.0)
        call TriggerSleepAction(0.)
        call CreateUnit(Player(0),'e00P',13883.0,-5760.0,0.0)
        call TriggerSleepAction(0.)
        call CreateUnit(Player(0),'e00P',14075.0,-5561.0,0.0)
        call TriggerSleepAction(0.)
        call MBSet( udg_SquadStatus, 1, 1, "Objective Completed : Power Generators Online" )
        call ALICE2Text(10.0, "Power Generator Online. |cff1e90ff100 XP|r awarded to all Marines." )
        set udg_MissionsCompleted=udg_MissionsCompleted+1
        loop
            exitwhen i>udg_InitialPlayers
            if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 100
            endif
            set i=i+1
        endloop
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],udg_UnknownEntities,bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(udg_UnknownEntities,bj_FORCE_PLAYER[9],bj_ALLIANCE_NEUTRAL)
        call GeneralText(3.0, "|cffcd950cMarine|r : We've got the power generators online. The spotlights on those towers will be useful." )
        call StartSound(gg_snd_Message)
        call CreateUnit(Player(9),'ex07',11219.0,-4930.0,0.0)
        call TriggerSleepAction(0.)
        set udg_Spotlight[1] = CreateUnit(Player(9),'e00O',11774.0,-5517.0,0.0) //Power Generator West Tower
        call IssuePointOrder(udg_Spotlight[1],"patrol",11444.0,-4679.0)
        call TriggerSleepAction(0.)

        call CreateUnit(Player(9),'ex07',13120.0,-3967.0,0.0)
        call TriggerSleepAction(0.)
        set udg_Spotlight[2] = CreateUnit(Player(9),'e00O',12660.0,-3335.0,0.0) //Power Generator North Tower
        call IssuePointOrder(udg_Spotlight[2],"patrol",13595.0,-3260.0)
        call TriggerSleepAction(0.)

        call CreateUnit(Player(9),'ex07',12550.0,5613.0,0.0)
        call TriggerSleepAction(0.)
        set udg_Spotlight[3] = CreateUnit(Player(9),'e00O',12333.0,4927.0,0.0) //Airfield South Tower
        call IssuePointOrder(udg_Spotlight[3],"patrol",13250.0,4955.0)
        call TriggerSleepAction(0.)

        call CreateUnit(Player(9),'ex07',12480.0,7792.0,0.0)
        call TriggerSleepAction(0.)
        set udg_Spotlight[4] = CreateUnit(Player(9),'e00O',11707.0,7750.0,0.0) //Airfield West Bottom Tower
        call IssuePointOrder(udg_Spotlight[4],"patrol",12113.0,6918.0)
        call TriggerSleepAction(0.)

        call CreateUnit(Player(9),'ex07',10566.0,9966.0,0.0)
        call TriggerSleepAction(0.)
        set udg_Spotlight[5] = CreateUnit(Player(9),'e00O',10060.0,9455.0,0.0) //Airfield West Top Tower
        call IssuePointOrder(udg_Spotlight[5],"patrol",10860.0,9195.0)
        call TriggerSleepAction(0.)

        call CreateUnit(Player(9),'ex07',12351.0,12857.0,0.0)
        call TriggerSleepAction(0.)
        set udg_Spotlight[6] = CreateUnit(Player(9),'e00O',11718.0,13112.0,0.0) //Airfield North Tower
        call IssuePointOrder(udg_Spotlight[6],"patrol",12312.0,13580.0)
        call StartSound(gg_snd_Message)
        set u = null
    endfunction

    private function PowerGeneratorArea takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local item i
        local integer id
        local integer inven = 0
        local integer added = 0
        local player p = GetOwningPlayer(u)
        if GetPlayerController(p)!=MAP_CONTROL_USER or GetUnitAbilityLevel(u,'Aloc')>0 then
            set u = null
            return
        endif
        loop
            exitwhen inven>5
            set i = UnitItemInSlot(u,inven)
            set id = GetItemTypeId(i)
            if id=='I00G' then //Energy Cell
                call RemoveItem(i)
                call RifleBolt(u)
                set udg_PowerGenerator=udg_PowerGenerator+1
                set added=1
            endif
            set inven=inven+1
        endloop
        set u = null
        set i = null
        if added==1 and udg_PowerGenerator==5 then
            call ALICEText(5.0,"One more Energy Cell required to restablish power.")
        elseif added==1 and udg_PowerGenerator<5 then
            call ALICEText(5.0,I2S(6-udg_PowerGenerator)+" more Energy Cells required to restablish power.")
        endif
        if udg_PowerGenerator>=6 then
            call PowerOn.execute()
            call DisableTrigger(GetTriggeringTrigger())
        endif
    endfunction

    private function Wave10e takes nothing returns nothing
        local integer i = 1
        local real x
        local real y
        local trigger t = CreateTrigger()
        
        local real trans = 0.0
        if udg_Players<1 or udg_Chapter==2 then
            return
        endif
        if GetRandomInt(0,10)==1 then
            set trans = 40.0
        endif
        call SetPlayerName( Player(9), "MAG-1" )
        set udg_Intermission = true
        set udg_XPFactor = udg_XPFactor * 1.1
        set udg_Chapter = 2
        set udg_Lighting = true
        call SquadRatingCalc.execute()
        call PauseAllUnitsBJ(true)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(false,1.0)
        call ClearTextMessages()
        call PolledWait(1.5)
        call StartSound(gg_snd_Message)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "                                                                                |cff8b864eNightstalkers|r" )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call PauseAllUnitsBJ(true)
        call PolledWait(5.5)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(true,1.0)
        call ClearTextMessages()
        set udg_Lighting = false
        call PolledWait(1.)
        set udg_Intermission = false
        call PauseAllUnitsBJ(false)
        call IntermissionRestore()
        call PolledWait(5.)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call TriggerSleepAction(0.)
        call IntermissionRestore()
        call SetImmortalSpawnEnabled(true)
        call SetCrepitusSpawnEnabled(true)
        call SetGhoulSpawnEnabled(true)
        call SetRevelationSpawnEnabled(true)
        
        set udg_CurrentWave = 10
        call GenericActions.execute()
        call PolledWait(5.)
        call GeneralText(10.0, "|cffcd950cIron Hand|r : It's getting real tough to get a signal through. You need to power up the power generators in your south east of your sector and restablish a stable communications channel with us." )
        call PolledWait(12.)
        call GeneralText(3.0, "|cffcd950cMarine|r : We need more light sources." )
        call PolledWait(6.)
        call Wave10Creeps.execute()
        call PolledWait(5.)
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Re-activate Power Generators" )
        call QuestSetDescription(udg_CurrentOrders, "Re-activate Power Generators. Energy Cells are required to restore power." )
        call ALICE2Text(5.0, "|cff8b864eNew Objective|r : Re-activate Power Generators." )
        call MissionUpdate.execute()
        call PolledWait(15.*udg_Pace)
        call GeneralText(3.0, "|cffcd950cIron Hand|r : We've airdropped some Field Lights at the Powe-" )
        call CreateItem('I014',13430.0,-5120.0)
        call TriggerSleepAction(0.)
        call CreateItem('I014',13430.0,-5120.0)
        call PolledWait(5.)
        call GeneralText(3.0, "|cffcd950cIron Hand|r : We're losing sign-" )
        call PolledWait(3.5)
        call GeneralText(3.0, "|cffcd950cIron Hand|r : You'll need six energy cells to resto-" )
        call PolledWait(3.5)
        call GeneralText(3.0, "|cffcd950cMarine|r : Iron Hand? Damn it." )
        call PolledWait(5.)
        call GeneralText(10.0, "|cffcd950cMarine|r : I think I saw some energy cells in the Windmill North West of our sector. Take a few men and check it out. The rest of us will head to the airfield and see if we can find anything useful." )
        loop
            exitwhen i>4
            call TriggerSleepAction(0.)
            set x = GetRandomReal(GetRectMinX(gg_rct_Home7),GetRectMaxX(gg_rct_Home7))
            set y = GetRandomReal(GetRectMinY(gg_rct_Home7),GetRectMaxY(gg_rct_Home7))
            call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",x,y))
            call CreateUnit(Player(13),'e00C',x,y,0.0)
            set x = GetRandomReal(GetRectMinX(gg_rct_Home7),GetRectMaxX(gg_rct_Home7))
            set y = GetRandomReal(GetRectMinY(gg_rct_Home7),GetRectMaxY(gg_rct_Home7))
            call CreateItem('I00G',x,y)
            call TriggerSleepAction(0.)
            set x = GetRandomReal(GetRectMinX(gg_rct_AirfieldDepot),GetRectMaxX(gg_rct_AirfieldDepot))
            set y = GetRandomReal(GetRectMinY(gg_rct_AirfieldDepot),GetRectMaxY(gg_rct_AirfieldDepot))
            call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",x,y))
            call CreateUnit(Player(14),'e00C',x,y,0.0)
            set x = GetRandomReal(GetRectMinX(gg_rct_AirfieldDepot),GetRectMaxX(gg_rct_AirfieldDepot))
            set y = GetRandomReal(GetRectMinY(gg_rct_AirfieldDepot),GetRectMaxY(gg_rct_AirfieldDepot))
            call CreateItem('I00G',x,y)
            set i=i+1
        endloop
        call TriggerRegisterEnterRectSimple(t,gg_rct_PowerGenerator)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_PowerGenerator)
        call TriggerAddAction(t,function PowerGeneratorArea)
        set t = null
        call PolledWait(80.)
        call ExecuteRegisteredFunction("Wave11e")
        //call Wave11e.execute()
    endfunction

    private function init takes nothing returns nothing
        call RegisterFunction("Wave10e", function Wave10e)
        // call ExecuteRegisteredFunction("Wave10e")
    endfunction


endlibrary

